﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Text.RegularExpressions;

namespace Empires.PL.PageHandler
{
    /// <summary>
    /// 防盗链
    /// </summary>
    public class VoidLinkAttribute : FilterAttribute, IActionFilter
    {
        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //获得请求来源
            string host = filterContext.HttpContext.Request.UrlReferrer.ToString();
            Regex reg = new Regex("(w{3}\\.)?(\\w+\\.)?cucmct\\.[\\w\\.]*", RegexOptions.IgnoreCase);
            if (!reg.IsMatch(host))
            {
                filterContext.HttpContext.Response.Redirect("/Home/Error", false);
            }
        }

        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            
        }
    }
}
